import request from '@/utils/request'

export async function login(data: any) {
  return request({
    url: '/api/User/Login',
    method: 'post',
    data,
  })
}

export async function socialLogin(data: any) {
  return request({
    url: '/socialLogin',
    method: 'post',
    data,
  })
}

export function getUserInfo() {
  return request({
    url: '/api/User/userInfo',
    method: 'get',
  })
}

export function logout() {
  return request({
    url: '/api/User/logout',
    method: 'get',
  })
}

let cachedUserList = null
export function getUserList() {
  if (cachedUserList) {
    return Promise.resolve(cachedUserList)
  }
  return request({
    url: '/api/User/getUserList',
    method: 'get',
  }).then((response) => {
    cachedUserList = response
    return response
  })
}

export function getUserFinancialList(data: any) {
  return request({
    url: '/api/User/getUserFinancialList',
    method: 'post',
    data,
  })
}

export function register(data: any) {
  return request({
    url: '/register',
    method: 'post',
    data,
  })
}
